package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.util.StrUtil;
import cn.lili.common.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 搜索参数
 *
 * @author Chopper
 * @since 2021/3/17 6:08 下午
 */
@Data
public class WithdrawLogSearchParams extends PageVO {

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "起始日期")
    private String startDate;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结束日期")
    private String endDate;


    /**
     * 枚举值：
     * CREATE_SUCCESS：受理成功
     * SUCCESS：提现成功
     * FAIL：提现失败
     * REFUND：提现退票
     * CLOSE：关单
     * INIT：业务单已创建
     */
    @ApiModelProperty(value = "预约提现单状态")
    private String status;

    @ApiModelProperty(value = "二级商户号")
    private String subMchid;


    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> wrapper = new QueryWrapper<>();

        //创建时间
        if (StrUtil.isNotBlank(startDate) && StrUtil.isNotBlank(endDate)) {
            wrapper.between("create_time", startDate, endDate);
        } else if (StrUtil.isNotBlank(startDate)) {
            wrapper.ge("create_time", startDate);
        } else if (StrUtil.isNotBlank(endDate)) {
            wrapper.le("create_time", endDate);
        }
        wrapper.like(StrUtil.isNotBlank(subMchid), "sub_mchid", subMchid);
        wrapper.eq(StrUtil.isNotBlank(status), "status", status);
        return wrapper;
    }
}
